package com.nf.health.app.mine.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.models.SystemHealthVo;
import com.nf.health.app.utils.ViewUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 系统方案  健康方案  详情页
 * Created by Administrator on 2016/3/30.
 */
public class SystemSchemeDetailActivity extends BaseActivity {

    String id, sport_name;

    String map, map2;

    @Bind(R.id.schemedatail_title)//title
            TextView schemedatailTitle;
    //    @Bind(R.id.schemedatail_image)//运动图片
//            ImageView schemedatailImage;
    @Bind(R.id.schemedatail_yl)//运动要领
            WebView schemedatailYl;
    //    @Bind(R.id.schemedatail_fs)//运动方式
//            TextView schemedatailFs;
//    @Bind(R.id.schemedatail_content)//内容
//            TextView schemedatailContent;
//    @Bind(R.id.schemedatail_cf)//重复
//            TextView schemedatailCf;
//    @Bind(R.id.schemedatail_cf_content)//天数
//            TextView schemedatailCfContent;
    @Bind(R.id.today_btn)
    Button todayBtn;
    @Bind(R.id.today_btn2)
    Button todayBtn2;
    @Bind(R.id.schemedatail_sport_name)
    TextView schemedatailSportName;//运动名称
    @Bind(R.id.down_btn)
    LinearLayout downBtn;
    private SystemHealthVo mlist;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_schemedatail);
        ButterKnife.bind(this);

        ViewUtil.setText(this, R.id.titlebar_title_tv, "计划详情");


        String type = getIntent().getStringExtra("type");


        if (TextUtils.isEmpty(type)) {//从系统健康方案跳过来  type 为空

            downBtn.setVisibility(View.GONE);

        } else {

            if (type.equals("1")) {
                todayBtn2.setVisibility(View.GONE);
                todayBtn.setVisibility(View.VISIBLE);
            } else {
                todayBtn.setVisibility(View.GONE);
                todayBtn2.setVisibility(View.VISIBLE);
            }
        }
        id = getIntent().getStringExtra("id");
        sport_name = getIntent().getStringExtra("sport_name");

        provider.requestHealthPlanUserById2(id, "HealthScheme");

        todayBtn.setOnClickListener(new View.OnClickListener() {//今日完成按钮

            @Override
            public void onClick(View v) {

                provider.requestUpdateHealthPlanUser(id, "UpdateHealthPlanUser");

            }
        });

        todayBtn2.setOnClickListener(new View.OnClickListener() {//今日完成按钮

            @Override
            public void onClick(View v) {

                provider.requestUpdateHealthPlanUser(id, "UpdateHealthPlanUser");

            }
        });

    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        if (actionName.equals("UpdateHealthPlanUser")) {
            showToast("今日已完成");
            provider.requestAddScore("7", "");//添加积分
            todayBtn.setVisibility(View.GONE);
            todayBtn2.setVisibility(View.VISIBLE);
        } else if (actionName.equals("HealthScheme")) {

            mlist = (SystemHealthVo) object;


            schemedatailTitle.setText(mlist.getName());//运动名称赋值

            schemedatailSportName.setText(mlist.getName());

            //  ImageLoaderUtils.getinstance(this).getImage(schemedatailImage, mlist.getUrl(), R.drawable.default_image);//图片赋值


            schemedatailYl.loadDataWithBaseURL(null, mlist.getRemark(), "text/html", "UTF-8", null);
        }
    }
}